<?php
include("/usr/local/apache2/htdocs/jibaiwang/lib/Tile.php");
include("/usr/local/apache2/htdocs/jibaiwang/lib/ImgStorage.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/bootstrap/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Tiles"]['qlogtag'];
Logger::configure($defarray["Series"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Tiles"]["host"];
$user = $defarray["Tiles"]["user"];
$pass = $defarray["Tiles"]["pass"];
$db = $defarray["Tiles"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Tile($dbh,$logger);
$a = new ImgStorage();

$tile_number = $_REQUEST["tile_number"];
$tile_length = $_REQUEST["tile_length"];
$tile_width = $_REQUEST["tile_width"];
$tile_texture = $_REQUEST["tile_texture"];
$tile_class = $_REQUEST["tile_class"];
$tile_series = $_REQUEST["tile_series"];

//var_dump($_REQUEST);
//$tile_series = $_REQUEST["tile_series"];
if ((($_FILES["tile_img"]["type"] == "image/gif")
    || ($_FILES["tile_img"]["type"] == "image/jgp")
    || ($_FILES["tile_img"]["type"] == "image/png")
    || ($_FILES["tile_img"]["type"] == "image/jpeg")
    || ($_FILES["tile_img"]["type"] == "image/pjpeg"))
    && ($_FILES["tile_img"]["size"] < 2000000))
{
    if ($_FILES["tile_img"]["error"] > 0)
    {
        echo "Return Code: " . $_FILES["tile_img"]["error"] . "<br />";
    }
    $buffer = file_get_contents($_FILES["tile_img"]["tmp_name"]);
    $ext = explode("/",$_FILES["tile_img"]["type"]);
    $img_url = $a->store($buffer, $ext[1]);
    $res = $s->createTile($tile_number, $tile_length,$tile_width,$tile_texture,$tile_class,$img_url,$img_url,$tile_series);
  
    //  echo $res;
}
else
{
    $alert =
          '<Script Language="JavaScript">
              alert("老板，文件过大或该文件不是图片，请重试。");
          </Script>';
          echo $alert;
          exit;
}
header("Location:Tile.php?tile_series=$tile_series");
